﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.services {
    import flash.events.*;
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import com.facebook.graph.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;

    public class FacebookGraphService extends Actor implements ISocialNetworkService {

		[Inject]
        public var sessionModel:SessionModel;

        namespace xmlNs = "http://api.facebook.com/1.0/";

        public function login(_arg1:Object):void{
            if (this.sessionModel.authToken){
                dispatch(new Event(CommandConstants.SOCIAL_NETWORK_CONNECTED));
            };
        }
        public function getFriends(_arg1:Function, _arg2:Function=null):void{
            this.sendFriendCall("get_friends", _arg1);
        }
        private function sendFriendCall(_arg1:String, _arg2:Function):void{
            var type = _arg1;
            var successHandler = _arg2;
            var callBack:Function = function (_arg1:ResultVO):void{
                var _local5:XML;
                var _local2:XML = XML(_arg1.data[type]);
                var _local3:XMLList = _local2..uid;
                var _local4:Array = [];
                for each (_local5 in _local3) {
                    _local4.push(_local5.children()[0]);
                };
                successHandler(_local4);
            };
            var request:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, callBack);
            request.addRequest(type, {access_token:this.sessionModel.authToken}, false, GameConstants.XML, ProtocolConstants.FACEBOOK_PIPE);
            dispatch(request);
        }
        public function getAppUsers(_arg1:Function, _arg2:Function=null):void{
            this.sendFriendCall("get_appusers", _arg1);
        }
        public function getInfo(_arg1:Array, _arg2:Array, _arg3:Function, _arg4:Function=null):void{
            var uids = _arg1;
            var fields = _arg2;
            var successHandler = _arg3;
            var failureHandler = _arg4;
            var callBack:Function = function (_arg1:ResultVO):void{
                var _local3:Object;
                var _local2:Array = [];
                for each (_local3 in _arg1.data.get_info) {
                    _local2.push(_local3);
                };
                successHandler(_local2);
            };
            var ids:String = uids.join(",");
            var field:String = fields.join(",");
            var request:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, callBack);
            request.addRequest("get_info", {ids:ids, fields:field}, false, GameConstants.JSON, ProtocolConstants.FACEBOOK_PIPE);
            dispatch(request);
        }
        private function onInit(_arg1:Object, _arg2:Object):void{
            Facebook.login(this.onLogin);
        }
        public function get isConnected():Boolean{
            return (!((this.sessionModel.authToken == null)));
        }
        private function onLogin(_arg1:Object, _arg2:Object):void{
        }

    }
}//package net.wooga.pets.services 
